home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / sprite.X11R3 / hdr / pr_util.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-03  |  3.9 KB  |  139 lines

  1. /* @(#)pr_util.h 1.18 88/02/08 SMI */
  2.  
  3. /*
  4.  * Copyright 1983, 1986, 1987 by Sun Microsystems, Inc.
  5.  */
  6.  
  7. #ifndef    pr_util_DEFINED
  8. #define    pr_util_DEFINED
  9.  
  10. /*
  11.  * WARNING:  This include file is obsolete and may disappear in the future.
  12.  *
  13.  * pr_product has been moved to pixrect.h
  14.  * struct pr_devdata etc. has been moved to pr_impl_make.h
  15.  * new loop macros are in pr_impl_util.h
  16.  */
  17.  
  18. /*
  19.  * Utilities for implementing pixrect operations.
  20.  */
  21.  
  22. /*
  23.  * Aids to handling overlapping source and destination.
  24.  * Given the from and to pr_pos's, rop_direction tells
  25.  * whether the rasterop is up or down and left or right,
  26.  * encoded as the ROP_UP and ROP_LEFT bits or their absence.
  27.  * The macros rop_is(up|down|left|right) can then be used.
  28.  */
  29. #define    ROP_UP        0x1
  30. #define    ROP_LEFT    0x2
  31.  
  32. #define    rop_direction(src, so, dst, do)    \
  33.         (   ( (((dst).x+(do).x) < ((src).x+(so).x)) << 1) | \
  34.               (((dst).y+(do).y) < ((src).y+(so).y))      )
  35. #define    rop_isleft(dir)        ((dir)&ROP_LEFT)
  36. #define    rop_isup(dir)        ((dir)&ROP_UP)
  37. #define    rop_isright(dir)    (((dir)&ROP_LEFT)==0)
  38. #define    rop_isdown(dir)        (((dir)&ROP_UP)==0)
  39.  
  40. /*
  41.  * Aids to producing fast loops, either unrolled or very tight:
  42.  *
  43.  * Cases8(n, op) produces the dense case part of a case statement
  44.  * for the cases [n+1..n+8), repeating ``op'' 1-8 times respectively.
  45.  *
  46.  * Rop_slowloop(n, op) produces a loop to do ``op'' n times, in little space.
  47.  * 
  48.  * Rop_fastloop(n, op) produces a loop to do ``op'' n times, in little time.
  49.  *
  50.  * Loop_d6(label, op) produces a dbra loop to do ``op'' the number of times
  51.  * in register d6 (second non-pointer register variable).
  52.  *
  53.  * Loop_d6 is only possible on a 68000 family processor, and rop_fastloop
  54.  * generates an unrolled loop only on a 68010 (assumes other processors 
  55.  * will have some kind of I-cache).
  56.  */
  57. #ifdef mc68000
  58. /* generates a nice dbra loop */
  59. #define    rop_slowloop(n, op) \
  60.     { register int _loop = (n); \
  61.         if (--_loop >= 0) do { op; } while (--_loop != -1); }
  62.  
  63. #define loopd6(label, op)                        \
  64.     if (0) {                            \
  65.         asm("label:");                        \
  66.         op;                            \
  67.     };                                \
  68.     asm("dbra    d6,label");
  69. #else mc68000
  70. #define    rop_slowloop(n, op) \
  71.     { register int _loop = (n); \
  72.         while (--_loop >= 0) { op; } }
  73. #endif mc68000
  74.  
  75. #ifdef mc68010
  76. #define cases8(n, op)                            \
  77.         case (n)+8: op; case (n)+7: op; case (n)+6: op;        \
  78.         case (n)+5: op; case (n)+4: op; case (n)+3: op;        \
  79.         case (n)+2: op; case (n)+1: op;                \
  80.  
  81. #define    rop_fastloop(n, op) \
  82.     { register int _loop ; \
  83.         for (_loop = (n); _loop > 15; _loop -= 16) \
  84.                 { op; op; op; op; op; op; op; op; \
  85.                     op; op; op; op; op; op; op; op; } \
  86.           switch (_loop) { \
  87.             cases8(8, op); \
  88.             cases8(0, op); \
  89.             case 0:    break; \
  90.         } }
  91. #else mc68010
  92. #define    rop_fastloop    rop_slowloop
  93. #endif mc68010
  94.  
  95. /*
  96.  * Alloctype(datatype) allocates a datatype structure using calloc
  97.  * with the appropriate type cast.
  98.  */
  99. #define    alloctype(datatype)                        \
  100.         (datatype *)calloc(1, sizeof (datatype))
  101.  
  102. /*
  103.  * Pr_product is used when doing multiplications involving pixrects,
  104.  * and casts its arguments to that the compiler will use 16 by 16 multiplies.
  105.  */
  106. #ifndef pr_product
  107. #ifdef sun
  108. #define pr_product(a, b)    ((short)(a) * (short)(b))
  109. #else
  110. #define pr_product(a, b)    ((a) * (b))
  111. #endif
  112. #endif
  113.  
  114. /*
  115.  * Pr_area is the area of a rectangle.
  116.  */
  117. #define pr_area(size) pr_product((size).x, (size).y)
  118.  
  119. /*
  120.  * Pr_devdata is used to keep track of the valloced/mmapped virtual
  121.  * address of a device to prevent doing it more than necessary.
  122.  */
  123. struct pr_devdata {
  124.     struct pr_devdata *next; /* link to next device of this type */
  125.     dev_t    rdev;        /* device type */
  126.     int    count;        /* reference count */
  127.     int    fd;        /* fd of frame buffer, -1 if unused */
  128.     short     *va;         /* virtual address */
  129.     int    bytes;        /* size of va, 0 for no munmap */
  130.     caddr_t    va2;        /* second virtual address, 0 if unused */
  131.     int    bytes2;        /* second size */
  132. };
  133.  
  134. #ifndef KERNEL
  135. Pixrect *pr_makefromfd();
  136. #endif !KERNEL
  137.  
  138. #endif pr_util_DEFINED
  139.